// 封装uni.showToast()成功函数
export const myShowToastSus = (opt) => {
	uni.showToast({
		title:opt
	})	
}
// 封装uni.showToast()失败函数
export const myShowToastErr = (opt) => {
	uni.showToast({
		title:opt,
		icon:'error'
	})	
}

export const switchSong = (songInfo,index) => {
	// 订阅方,来自songDetail传过来的参数type
	uni.$on('switchType',(type) => {
		console.log(type,'我要切歌了');
		if(type === 'pre'){ // 切换上一首
		// if(this.index === 0){this.index = this.recommendList.length}
		// 等同于上面,如果是第一首歌切换上一首 就是播放最后一首 length-1 就是数组最后一个
			(index === 0) && (index = songInfo.length)
			index -= 1
		}else {// 切换下一首
			if(index === songInfo.length - 1) {index = -1}
			// (this.index === this.recommendList.length - 1) && (this.index = -1)
			index += 1
		}
		let musicId = songInfo[index].id
		// 将musicId 回传给songDetail页面
		uni.$emit('musicId',musicId)
		console.log(musicId,'recommendSong');
	})
}




















/*
main.js引入

Vue.prototype.ScanAudio = function() {
	var music = null;
	music = uni.createInnerAudioContext(); //创建播放器对象
	music.src = "../../static/mp3/fy-cn.mp3";
	music.play(); //执行播放
	music.onEnded(() => {
		//播放结束
		music = null;
	});
}

页面中调用
//这里接口需要请求，判断是否需要播放语音提示
this.ScanAudio();//播放语音
*/